package org.springblade.core.log.wrapper;

import org.springblade.core.log.entity.LogAudit;
import org.springblade.core.log.vo.LogAuditVO;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.system.cache.SysCache;
import org.springblade.system.entity.Tenant;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.UserInfo;

/**
 * LogAuditWrapper
 * @author lijiamin
 */
public class LogAuditWrapper extends BaseEntityWrapper<LogAudit, LogAuditVO> {

	public static LogAuditWrapper build() {
		return new LogAuditWrapper();
	}

	@Override
	public LogAuditVO entityVO(LogAudit entity) {
		LogAuditVO logAuditVO = BeanUtil.copy(entity, LogAuditVO.class);

		if (logAuditVO.getUserId() == null) {
			return logAuditVO;
		}

		UserInfo userInfo = UserCache.getUserClient().userInfo(logAuditVO.getUserId()).getData();
		Tenant tenant = SysCache.getSysClient().getTenant(userInfo.getUser().getTenantId()).getData();
		logAuditVO.setRealName(userInfo.getUser().getRealName());
		logAuditVO.setTenantName(tenant.getTenantName());

		return logAuditVO;
	}
}
